package com.magicsoft.share.presenter.my;

import com.magicsoft.share.base.BasePresenter;
import com.magicsoft.share.bean.my.MessageList;
import com.magicsoft.share.constant.APIService;
import com.magicsoft.share.constant.SPKey;
import com.magicsoft.share.rx_retrofit_network.location.retrofit.RetrofitUtil;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.LoadingTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.NetWorkTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.SimpleObserver;
import com.magicsoft.share.utils.SPUtils;
import com.magicsoft.share.view.my.IMessageListView;

import static android.R.attr.type;

/**
 * Created by lyf on 2017/11/23/023.
 */

public class MessageListPresenter extends BasePresenter<IMessageListView> {
    public void messageList(int msgType,int pageNum, int pageSize) {
        RetrofitUtil.getApi(APIService.class).messageList(SPUtils.getInstance().getString(SPKey.TOKEN), SPUtils.getInstance().getLong(SPKey.ID),
                msgType, pageNum, pageSize)
                .compose(new NetWorkTransformer<MessageList>())
                .compose(new LoadingTransformer<MessageList>(mContext))
                .subscribe(new SimpleObserver<MessageList>(mCompositeDisposable) {
                    @Override
                    public void call(MessageList messageList) {

                        getView().messageListSuccess(messageList);
                    }

                    @Override
                    public void showErrorMsg(Throwable e, String errorMsg) {
                        super.showErrorMsg(e, errorMsg);
                        getView().messageListFail();
                    }
                });

    }
}
